package com.yss.processor;

import com.yss.RouterMain;
import com.yss.netty.processor.AbstractHandlerProcessor;
import com.yss.netty.processor.ProcessorResultInfo;
import com.yss.netty.protocol.CommandType;
import com.yss.netty.protocol.SerType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BondProcessor extends AbstractHandlerProcessor {

    @Autowired
    private RouterMain routerMain;

    /**
     * 同一个Processor可以应对多个CommandType 避免类膨胀
     *
     * @param commandType
     * @param params
     * @return
     */
    @Override
    public ProcessorResultInfo handle(final CommandType commandType, final Object params) {
        List<Object> result = routerMain.calculation(params);
        ProcessorResultInfo resultInfo = null;
        switch (commandType) {
            case BOND: {
                resultInfo = ProcessorResultInfo.builder().serType(SerType.JSON).commandType(CommandType.BOND).handleResult(result.get(0)).build();
                break;
            }
        }
        return resultInfo;
    }
}
